import axios, {ResponseData} from 'yuxin-base/src/utils/axios'
import {isLockinEnv} from 'yuxin-base/src/utils'

export interface T_GRANT_CODE {
	code: string
	endTime: string
	startTime: string
}

export function getLockList(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/device/list',
		data,
		method: 'POST'
	})
}

export function getLockCount(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/access/control/list',
		data,
		method: 'POST'
	})
}

export function getLockDetail(deviceId: string): Promise<ResponseData> {
	return axios.request({
		url: '/saas-rental-device/device/device/get',
		params: {
			deviceId,
			deviceType: 5,
			withOrigin: !isLockinEnv()
		},
		method: 'GET'
	})
}

export function getLockLicense(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/list',
		data,
		method: 'POST'
	})
}

export function getLockOpenRecord(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/access/control/list',
		data,
		method: 'POST'
	})
}

export function sendGrant(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/access/control/list',
		data,
		method: 'POST'
	})
}

export function sendGrantPwd(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/grant_pwd',
		data,
		method: 'POST'
	})
}

export function sendGrantPwdWithoutCenter(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/grant_pwd_without_center',
		data,
		method: 'POST'
	})
}

export function sendGrantTenantPwd(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/contract/contract/grant_tenant_pwd',
		data,
		method: 'POST'
	})
}

export function sendGrantTenantPwdWithoutCenter(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/contract/contract/grant_tenant_pwd_without_center',
		data,
		method: 'POST'
	})
}

export function sendGrantCoTenantPwd(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/grant_pwd',
		data,
		method: 'POST'
	})
}

export function deleteGrant(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/delete',
		data,
		method: 'POST'
	})
}

export function frozenGrant(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/frozen',
		data,
		method: 'POST'
	})
}

/** 获取冻结码 */
export function frozenGrantByCode(data: object): Promise<ResponseData<T_GRANT_CODE>> {
	return axios.request({
		url: '/device/lock_auth/frozen_code',
		data,
		method: 'POST'
	})
}

/** 获取解冻码 */
export function unfrozenGrantByCode(data: object): Promise<ResponseData<T_GRANT_CODE>> {
	return axios.request({
		url: '/device/lock_auth/unfrozen_code',
		data,
		method: 'POST'
	})
}

/** 获取删除码 */
export function deleteGrantByCode(data: object): Promise<ResponseData<T_GRANT_CODE>> {
	return axios.request({
		url: '/device/lock_auth/delete_code',
		data,
		method: 'POST'
	})
}

export function grantAgain(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/grant_again',
		data,
		method: 'POST'
	})
}

export function bindLocks(data: object): Promise<ResponseData> {
	return axios.request({
		url: 'saas-rental-device/device/device/bind',
		data,
		method: 'POST'
	})
}

export function unbindLock(id: string): Promise<ResponseData> {
	return axios.request({
		url: `/device/device/unbind/${id}`,
		method: 'POST'
	})
}

//后付费解绑电表
export function unbindAddBill(data: any): Promise<ResponseData> {
	return axios.request({
		url: '/device/device/unbind_add_bill',
		data,
		method: 'POST'
	})
}

export function getOperations(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/system/log_manager/operation_log_pages',
		data,
		method: 'POST'
	})
}

export function getExceptions(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/device/exceptions',
		data,
		method: 'POST'
	})
}

export function getOncePwd(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/grant_once_pwd',
		data,
		method: 'POST'
	})
}

export function getDynamicPwd(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/grant_dynamic_pwd',
		data,
		method: 'POST'
	})
}

export function grantAdminPwd(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/grant_admin_pwd',
		data,
		method: 'POST'
	})
}

export function grantOfflineAdminPwd(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/grant_admin_pwd_without_center',
		data,
		method: 'POST'
	})
}

export function sendGrantNfc(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/grant_card',
		data,
		method: 'POST'
	})
}

export function sendGrantTenantNfc(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/contract/contract/grant_tenant_card',
		data,
		method: 'POST'
	})
}

export function sendGrantTenantBle(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/contract/contract/grant_tenant_ble_key',
		data,
		method: 'POST'
	})
}

export function sendGrantBle(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/grant_ble_key',
		data,
		method: 'POST'
	})
}

export function getFpsKey(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/get_fps_key',
		data,
		method: 'POST'
	})
}

export function sendGrantFp(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/device/lock_auth/grant_fps',
		data,
		method: 'POST'
	})
}

export function sendGrantTenantFp(data: object): Promise<ResponseData> {
	return axios.request({
		url: '/contract/contract/grant_tenant_fps',
		data,
		method: 'POST'
	})
}

export function updateLockAuth(data: object) {
	return axios.request({
		url: '/device/lock_auth/update',
		data,
		method: 'POST'
	})
}
export function grantTenantBleKey(data: object) {
	return axios.request({
		url: '/contract/contract/grant_tenant_ble_key',
		data,
		method: 'POST'
	})
}


/**
 * 判断设备是否设置能耗费
 * @param data
 */
export const isSetEnergyCost = (roomId): Promise<ResponseData> => {
	return axios.request({
		url: `/device/energy_cost_room_setting/house_setting/${roomId}`,
		method: 'GET'
	})
}
